<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page trimDirectiveWhitespaces="true"%>
<%@ page isELIgnored="false"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="ujn" uri="http://ujn.edu.cn/common/"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>支付信息</title>
<!-- 引入css样式文件 -->
<!-- Bootstrap Core CSS -->
<link href="<%=basePath%>css/bootstrap.min.css" rel="stylesheet" />
<!-- MetisMenu CSS -->
<link href="<%=basePath%>css/metisMenu.min.css" rel="stylesheet" />
<!-- DataTables CSS -->
<link href="<%=basePath%>css/dataTables.bootstrap.css" rel="stylesheet" />
<!-- Custom CSS -->
<link href="<%=basePath%>css/sb-admin-2.css" rel="stylesheet" />
<!-- Custom Fonts -->
<link href="<%=basePath%>css/font-awesome.min.css" rel="stylesheet"
	type="text/css" />
<link href="<%=basePath%>css/boot-crm.css" rel="stylesheet"
	type="text/css" />
<style>
body {
	padding-top: 20px;
}

.table thead {
	background-color: #f5f5f5;
}
</style>
</head>
<body>

	<div id="page-wrapper">
		<div class="row">
			<div class="col-lg-12">
				<h1 class="page-header">支付信息</h1>
			</div>
			<!-- /.col-lg-12 -->
		</div>
		<!-- /.row -->
		<a href="#" class="btn btn-primary" data-toggle="modal"
			data-target="#newPaymentDialog" onclick="clearPayment()">新建</a>


		<div class="panel panel-default">
			<div class="panel-body">
				<form class="form-inline" method="get"
					action="${pageContext.request.contextPath }/payment/list.action">
					<button type="submit" class="btn btn-primary">查询所有支付信息</button>
				</form>
			</div>
		</div>
		<div class="row">
			<div class="col-lg-12">
				<div class="panel panel-default">
					<!-- /.panel-heading -->
					<table class="table table-bordered table-striped">
						<thead>
							<tr>
								<th>支付编号</th>
								<th>订单编号</th>
								<th>支付方式</th>
								<th>支付时间</th>
								<th>操作</th>
							</tr>
						</thead>
						<tbody>
							<c:forEach items="${page.rows}" var="row">
								<tr>
									<td>${row.paymentid}</td>
									<td>${row.orderid}</td>
									<td>${row.paymentmethod}</td>
									<td>${row.paymentdate}</td>
									<td><a href="#" class="btn btn-primary btn-xs"
										data-toggle="modal" data-target="#paymentEditDialog"
										onclick="editPayment(${row.paymentid})">修改</a> <a href="#"
										class="btn btn-danger btn-xs"
										onclick="deletePayment(${row.paymentid})">删除</a></td>
								</tr>
							</c:forEach>
						</tbody>
					</table>
					<div class="col-md-12 text-right">
						<ujn:page
							url="${pageContext.request.contextPath }/payment/list.action" />
					</div>
					<!-- /.panel-body -->
				</div>
				<!-- /.panel -->
			</div>
			<!-- /.col-lg-12 -->
		</div>
	</div>


	<!-- 创建支付模态框 -->
	<div class="modal fade" id="newPaymentDialog" tabindex="-1"
		role="dialog" aria-labelledby="myModalLabel">
		<div class="modal-dialog" role="document">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal"
						aria-label="Close">
						<span aria-hidden="true">&times;</span>
					</button>
					<h4 class="modal-title" id="myModalLabel">创建支付信息</h4>
				</div>
				<div class="modal-body">
					<form id="new_payment_form">
						<div class="form-group">
							<label for="editedorderId">订单编号:</label> <input type="text"
								id="neworderId" name="orderid">
						</div>
						<div class="form-group">
							<label for="newPaymentMethod">支付方式:</label> <select
								id="newPaymentMethod" name="paymentmethod">
								<option value="支付宝">支付宝</option>
								<option value="微信">微信</option>
								<option value="信用卡">信用卡</option>
								<option value="花呗">花呗</option>
								<option value="银行卡">银行卡</option>
							</select>
						</div>
					</form>
				</div>
				<div class="modal-footer">
					<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
					<button type="button" class="btn btn-primary"
						onclick="createPayment()">创建支付信息</button>
				</div>
			</div>
		</div>
	</div>


	<!-- 修改评论模态框 -->
	<div class="modal fade" id="paymentEditDialog" tabindex="-1"
		role="dialog" aria-labelledby="myModalLabel">
		<div class="modal-dialog" role="document">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal"
						aria-label="Close">
						<span aria-hidden="true">&times;</span>
					</button>
					<h4 class="modal-title" id="myModalLabel">修改支付信息</h4>
				</div>
				<div class="modal-body">
					<form id="editPaymentForm">
						<div class="form-group">
							<label for="editedpaymentId">支付编号:</label> <input type="number"
								id="paymentid" name="paymentid" readonly="readonly">
						</div>
						<div class="form-group">
							<label for="editedorderId">订单编号:</label> <input type="text"
								id="editedorderId" name="orderid" readonly="readonly">
						</div>
						<div class="form-group">
							<label for="editedPaymentMethod">支付方式:</label> <select
								id="editedPaymentMethod" name="paymentmethod">
								<option value="支付宝">支付宝</option>
								<option value="微信">微信</option>
								<option value="信用卡">信用卡</option>
								<option value="花呗">花呗</option>
								<option value="银行卡">银行卡</option>
							</select>
						</div>
						<div>
							<label for="editedpaymentDate">支付时间:</label> <input type="text"
								id="editedpaymentDate" name="paymentdate" readonly="readonly">
						</div>
					</form>
				</div>
				<div class="modal-footer">
					<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
					<button type="button" class="btn btn-primary"
						onclick="updatePayment()">保存修改</button>
				</div>
			</div>
		</div>
	</div>


	<!-- 引入js文件 -->
	<!-- jQuery -->
	<script src="<%=basePath%>js/jquery-1.11.3.min.js"></script>
	<!-- Bootstrap Core JavaScript -->
	<script src="<%=basePath%>js/bootstrap.min.js"></script>
	<!-- Metis Menu Plugin JavaScript -->
	<script src="<%=basePath%>js/metisMenu.min.js"></script>
	<!-- DataTables JavaScript -->
	<script src="<%=basePath%>js/jquery.dataTables.min.js"></script>
	<script src="<%=basePath%>js/dataTables.bootstrap.min.js"></script>
	<!-- Custom Theme JavaScript -->
	<script src="<%=basePath%>js/sb-admin-2.js"></script>
	<!-- 编写js代码 -->
	<script type="text/javascript">
	//清空新建客户窗口中的数据
	function clearPayment() {
	    $("#neworderId").val("");
	    $("#newPaymentMethod").val("")
	}
	//创建支付
	function createPayment() {
		$.post("<%=basePath%>payment/create.action",
		$("#new_payment_form").serialize(),function(data){
		        if(data =="OK"){
		            alert("支付信息创建成功！");
		            window.location.reload();
		        }else{
		            alert("支付信息创建失败！");
		            window.location.reload();
		        }
		    });
		}
	
	// 删除支付信息
	function deletePayment(id) {
	    if(confirm('确实要删除该支付信息吗?')) {
	$.post("<%=basePath%>payment/delete.action",{"id":id},
	function(data){
	            if(data =="OK"){
	                alert("支付信息删除成功！");
	                window.location.reload();
	            }else{
	                alert("支付信息删除失败！");
	                window.location.reload();
	            }
	        });
	    }
	}
	

    // 执行修改支付操作
	function updatePayment() {
		$.post("<%=basePath%>payment/update.action",$("#editPaymentForm").serialize(),function(data){
			if(data =="OK"){
				alert("支付信息更新成功！");
				window.location.reload();
			}else{
				alert("支付信息更新失败！");
				window.location.reload();
			}
		});
	}

    
	function editPayment(id) {
	    $.ajax({
	        type:"get",
	        url:"<%=basePath%>payment/getPaymentById.action",
	        data:{"id":id},
	        success:function(data) {
	            $("#paymentid").val(data.paymentid);
	            $("#editedorderId").val(data.orderid);
	            $("#editedPaymentMethod").val(data.paymentmethod);
	            $("#editedpaymentDate").val(data.paymentdate);
	        }
	    });
	}
    

    
	</script>
</body>
</html>
